<?php 
/**
 * 抽奖用户
 */
class Module_telephone{
	/**
	 * 构造函数
	 */
	function __construct(){
	
	}
	function index(){
	}
	/**
	 * 抽奖首页
	 */
	function lucky(){
		
		$smarty = loadSmarty();
		
		loadLib('Activity');
		//获取抽奖数据
		$draw=Activity::getRandAll();
		//print_r($draw);
		$smarty->assign('draw' , $draw);

		return $smarty->fetch('telephone_act/lucky.tpl.php');
	}
	/**
	 * 开始抽奖
	 * Enter description here ...
	 */
	function openlucky(){
		//取得复选框的值
		$array= isset($_POST['checkbox']) ? ($_POST['checkbox']) : '';

		if(empty($array)){
			return Format::json_return(1 , '没有选择 抽奖对象');
		}
		
		$smarty = loadSmarty();
		$count = count($array);
		loadLib('Activity');
		
		$code = Activity::getUpdate(implode(",",$array));
		if($code === 0) {
			$list = Activity::getAllDrawAc(implode(",",$array));
			loadLib('SysMsg');
			foreach ($list as $k => $row){
				SysMsg::sendSystem($row['uin'] , array(
				'send_uin' => $row['uin'],
				) , 1004);
			}
		}
		return Format::json_return(0 , '选中('.$count.'人),抽奖成功！',$array);
	}
	/**
	 * 删除抽奖用户页面
	 */
	function delete(){
		$page = isset($_GET['page']) ? intval($_GET['page']) : null;
		
		$smarty = loadSmarty();
		
		//设置每行10条数据
		$per_page = 10;
		if($page <= 0){
			$page = 1;
		}
		loadLib('Activity');
		//获取抽奖数据总量
		$lucky_count = Activity::getCount();
		//获取抽奖数据
		$draw=Activity::getAll($page,$per_page);
		
		$smarty->assign('draw' , $draw);
		$smarty->assign('lucky_count' , $lucky_count);
		$smarty->assign('per_page' , $per_page);
		return $smarty->fetch('telephone_act/delete.tpl.php');
	}
	/**
	 * 执行删除
	 * Enter description here ...
	 */
	function updelete(){
		$array= isset($_POST['checkbox']) ? $_POST['checkbox'] : '';
		
		if(empty($array)){
			return Format::json_return(1 , '没有选择 删除对象');
		}
		$smarty = loadSmarty();
		
		loadLib('Activity');
		$code = Activity::getDelete(implode(",",$array)); 
		return Format::json_return(0 , '删除成功！');
	}
}

# end of script